package com.hc.wdj.core.httpauth.basic;

import com.hc.wdj.core.context.HcHolder;
import com.hc.wdj.core.secure.Base64Util;

/**
 * @author ryanwdj
 * @since 2024/11/20
 */
public class HttpBasicTemplate {

    /**
     * 获取浏览器提交的Basic参数
     * @return
     */
    public String getAuthorizationValue(){
        // 获取前端提交的请求头 Authorization 参数
        String authorization = HcHolder.getRequest().getHeader("Authorization");

        // 如果不是以 Basic 作为前缀，则视为无效
        if(authorization == null || !authorization.startsWith("Basic ")){
            return null;
        }

        //裁剪前缀并解码
        return Base64Util.decode(authorization.substring(6));
    }
}
